import datetime
import multiprocessing
from util import *
import copy
from CloudSystem import run_once
import gc


def generate_default_args():
    args=Args()
    
    args.request_num=10000
    args.print_level=0
    args.out_dir="output_part"
    args.bare_metal_node_num=20
    args.time_expand=0.1
    args.state_resource_percent=0.3
    args.spec_reliability=0.9999
    return args


def run_once_this(method,  part_percent_min, part_percent_max, trace_id):
    print(f"start once {method}, {part_percent_min}, {part_percent_max}, {trace_id}")
    args=generate_default_args()
    
    args.deploy_schedule_strategy=method
    args.part_percent_min=part_percent_min
    args.part_percent_max=part_percent_max
    args.trace_id=trace_id
    args_copy=copy.deepcopy(args)
    run_once(args_copy)
    gc.collect()
    print(f"End once {method}, {part_percent_min}, {part_percent_max}, {trace_id}")
    
    



task_args_list=[]
for trace_id in range(10):
    for part_percent_min in [0,0.2,0.4,0.6,0.8]:
        for method in ["ours", "RR","C_GM","GSMS","QFEC","R_RIR"]:#
            task_args_list.append((method, part_percent_min, part_percent_min+0.2, trace_id))
        
                

with multiprocessing.Pool(processes=32) as pool:
        # 使用 starmap 方法将任务分配给进程池中的进程执行
        pool.starmap(run_once_this, task_args_list)


    
print("End all sub threadings")
